# coding:utf-8
import os


def printMenu():
    print("-" * 15)
    print("0. 退出")
    print("1. 添加学生")
    print("2. 查询学生")
    print("3. 查询所有学生")
    print("-" * 15)
    return input("请输入选项：")


def addStudent():
    global studentList
    studentDict = {}
    id = input("请输入学号：")
    if not checkNotBlank(id):
        return
    studentDict["id"] = id
    name = input("请输入姓名：")
    if not checkNotBlank(name):
        return
    studentDict["name"] = name
    studentList.append(studentDict)


def findStudent(all):
    global studentList
    idInput = None
    if not all:
        idInput = input("请输入学号：")

    print("学号   姓名")
    for s in studentList:
        if idInput is not None and idInput.strip() != "":
            if s["id"] == idInput:
                print(s["id"], "  ", s["name"])
        else:
            print(s["id"], "  ", s["name"])


def checkNotBlank(info) -> bool:
    if info is None or info.strip() == "":
        print("输入的信息为空");
        return False
    return True


if __name__ == "__main__":
    studentList = []
    while True:
        option = printMenu()
        if option == "0":
            break
        os.system("cls")
        if option == "1":
            addStudent()
        if option == "2":
            findStudent(False)
        if option == "3":
            findStudent(True)
